<?php

namespace App\Http\Controllers\Guard\Index;

use App\Http\Controllers\Common\GuardController;
use App\Models\Student\Ask;
use App\Models\Student\Student;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;


class IndexController extends GuardController {

    public function index(Request $request){

        $days = getMonthDays();

        //---------------------------------------------------------------------------------------------
        $countAllStudent  = Student::count();//总报名数
        $studentMonth = Student::whereYear('created_at',date('Y'))->whereMonth('created_at',date('m'))
            ->orderBy('created_at')->get(['id','created_at'])->map(function ($item){
                $item->day = date('Y-m-d',strtotime($item->created_at));
                return $item;
            });

        $mapDayStudent = [];//当月每天报名数
        foreach ($days as $day) {
            $mapDayStudent[] = $studentMonth->where('day',$day)->count();
        }

        $countCurrentMonthStudent = $studentMonth->count();//当月报名数

        //---------------------------------------------------------------------------------------------
        $countAllAsk = Ask::count();//咨询总数
        $currentMonthAsk = Ask::whereYear('created_at',date('Y'))->whereMonth('created_at',date('m'))
            ->orderBy('created_at')->get(['id','created_at'])->map(function ($item){
                $item->day = date('Y-m-d',strtotime($item->created_at));
                return $item;
            });
        $mapDayStudentAsk = [];
        foreach ($days as $day) {
            $mapDayStudentAsk[] = $currentMonthAsk->where('day',$day)->count();
        }
        $countCurrentMonthAsk = $studentMonth->count();

        //---------------------------------------------------------------------------------------------
        $countAllInterView = DB::table('student_interview_log')->count();//面试总数

        //---------------------------------------------------------------------------------------------
        $countSiteScan = DB::table('site_scan_count')->orderBy('date')->pluck('count')->toArray();


        return responseSuccess(compact(
            'countAllStudent','mapDayStudent','countCurrentMonthStudent',
            'countAllAsk','mapDayStudentAsk','countCurrentMonthAsk',
            'countAllInterView',
            'countSiteScan'
        ));
    }
}
